package net.alan.etl.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import net.alan.etl.i.IFlowTask;

/**
 * @author 李岩飞
 * @email eliyanfei@126.com
 * @date 2018年5月11日下午1:50:06
 */
public class FlowProxyFactory implements InvocationHandler {
	// 维护一个目标对象
	private IFlowTask target;

	public FlowProxyFactory(IFlowTask target) {
		this.target = target;
	}

	// 给目标对象生成代理对象
	public Object getFlowTask() {
		return Proxy.newProxyInstance(target.getClass().getClassLoader(),
				new Class[] { Runnable.class, IFlowTask.class }, this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		Object returnValue = method.invoke(target, args);
		return returnValue;
	}

}
